home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / computer.lua < prev    next >
Text File  |  2004-01-29  |  5KB  |  187 lines

  1. -- computer state machine
  2.  
  3. beginStateMachine()
  4.  
  5.  
  6.     onEnter(function(msg)
  7.         setState("off");
  8.     end )
  9.  
  10.     
  11.     onMsg("buildMenu", function(msg)
  12.     
  13.         if (repairMenu()) then return end
  14.         
  15.         local character = getStateObjectFromID(msg.sender);
  16.     
  17.         -- build the pie menu
  18.         clearPieMenu();
  19.         local button ;
  20.         
  21. --        button = addPieMenuButton("pm_chat", "chat");
  22. --        button.addDescription(ACTIVITY, "chatComputer");
  23. --
  24. --        button = addPieMenuButton("pm_play", "play");
  25. --        button.addDescription(ACTIVITY, "playComputer");
  26.         
  27.         --local isUsing = isUser(character, this, PC_ACTIVITIES);
  28.  
  29.  
  30.  
  31.         if (not isUser(character, this, {"playComputer"})) then
  32.             button = addPieMenuButton("pm_play", "use", "play");
  33.             button.addDescription(ACTIVITY, "playComputer");
  34.             --if (isUsing) then button.addDescription(DONTQUEUE, "true"); end;
  35.         end
  36.         
  37.         if (not isUser(character, this, {"chatComputer"})) then
  38.             button = addPieMenuButton("pm_chat", "use", "chat");
  39.             button.addDescription(ACTIVITY, "chatComputer");
  40.             --if (isUsing) then button.addDescription(DONTQUEUE, "true"); end;
  41.         end
  42.         
  43.         
  44.     end )
  45.     
  46.     -- chat on the computer
  47.     onMsg("use", function(msg)
  48.         -- get the game object server
  49.         local gameObjectServer = getGameObjectServer();
  50.         -- get character who initiated this action
  51.         local character = getStateObjectFromID(msg.sender);
  52.         -- get the walk state object
  53.         local wso = character.walkSO;
  54.         -- which program to use
  55.         local program = msg.data;
  56.         
  57. --        if (isUser(character, this, PC_ACTIVITIES)) then
  58. --            --character allready using this PC:  send switch msg
  59. --            print(" PC onMsg use is User" .. wso.getStateMachine().getName() .. "." .. wso.getState());    
  60. --            sendMsg("switch", wso, msg.data);
  61. --        else        
  62.             -- check if computer is on table and retrieve the chair
  63.             local chair = getChairForItemOnTable(this);
  64.             if (chair) then
  65.                 -- get the chairs action point
  66.                 local actionPoint = character.getClosestFreeActionPoint(character, chair, {"sit1", "sit2"} );
  67.                 if (actionPoint) then
  68.                     if (wso.walkToActionPoint(actionPoint)) then
  69.                         -- create state machine contexts
  70.                         local wsoContext = StateMachineContext();
  71.                         -- store the action point
  72.                         wsoContext.storeData("actionPointName", actionPoint.getName());
  73.                         wsoContext.storeData("program", program);
  74.                                                 
  75.                         wso.queueStateMachine("computerChar.sitDown", this, wsoContext);
  76.                     else
  77.                         print("no path found");
  78.                         instantAbort(character, EMOTICON_NOPATH, "emoThink")
  79.                     end
  80.                 else
  81.                     print("no action point found");
  82.                     instantAbort(character, EMOTICON_CANNOT, "emoThink")
  83.                 end
  84.             else 
  85.                 print("no chair found");
  86.                 instantAbort(character, EMOTICON_NOSEAT, "emoThink")
  87.             end
  88. --        end
  89.         
  90.         
  91.     end )
  92.     
  93. --    -- play on the computer
  94. --    onMsg("play", function(msg)
  95. --                -- get the game object server
  96. --        local gameObjectServer = getGameObjectServer();
  97. --        -- get character who initiated this action
  98. --        local character = getStateObjectFromID(msg.sender);
  99. --        -- check if computer is on table and retrieve the chair
  100. --        local chair = getChairForItemOnTable(this);
  101. --        if (chair) then
  102. --            -- get the chairs action point
  103. --            local actionPoint = character.getClosestFreeActionPoint(character, chair, {"sit1", "sit2"});
  104. --            -- get the walk state object
  105. --            local wso = character.walkSO;
  106. --            if (actionPoint) then
  107. --                -- create state machine contexts
  108. --                local wsoContext = StateMachineContext();
  109. --                -- store the action point
  110. --                wsoContext.storeData("actionPointName", actionPoint.getName());
  111. --                if (wso.walkToActionPoint(actionPoint)) then
  112. --                    wso.queueStateMachine("computerChar.sitDownPlay", this, wsoContext);
  113. --                else
  114. --                    print("no path found");
  115. --                    instantAbort(character, EMOTICON_NOPATH, "emoThink")
  116. --                end
  117. --            else
  118. --                print("no action point found");
  119. --                instantAbort(character, EMOTICON_CANNOT, "emoThink")
  120. --            end
  121. --        else 
  122. --            print("no chair found");
  123. --            instantAbort(character, EMOTICON_NOSEAT, "emoThink")
  124. --        end
  125. --    end )
  126.     
  127.     
  128.     
  129.     
  130.     state("off")
  131.     
  132.         onEnter(function(msg)
  133.             print("Comp off enter ----------------------------");            
  134.             replaceTexture("tvOff", "tvOff");            
  135.             --stopAllSounds();
  136.         end )
  137.     
  138.         
  139.         onExit(function(msg)
  140.             playSound("computerStartup");
  141.         end )        
  142.         
  143.     state("play")
  144.     
  145.         onEnter(function(msg)
  146.             print("Comp play enter ----------------------------");
  147.             sendMsgThis("startAnim");
  148.         end )
  149.         
  150.         onExit(function(msg)
  151.         end )        
  152.         
  153.         
  154.         onMsg("startAnim", function(msg)
  155.             startAnim({"pcGame1", "pcGame2", "pcGame3", "pcGame4", "pcGame3", "pcGame2"});
  156.         end )
  157.     
  158.         onMsg("showPic", function(msg)
  159.             replaceTexture("tvOff", msg.data);
  160.         end )
  161.     
  162.     
  163.     state("chat")
  164.     
  165.         onEnter(function(msg)
  166.             print("Comp chat enter ----------------------------");
  167.             sendMsgThis("startAnim");
  168.         end )
  169.         
  170.         onExit(function(msg)
  171.         end )        
  172.         
  173.         
  174.         onMsg("startAnim", function(msg)
  175.             startAnim({"pcChat1", "pcChat2", "pcChat3", "pcChat4"}, 3000);
  176.         end )
  177.     
  178.         onMsg("showPic", function(msg)
  179.             replaceTexture("tvOff", msg.data);
  180.         end )
  181.     
  182.     
  183.     
  184.     
  185.             
  186. endStateMachine()
  187.